function navTo(path: string) {
  const url = `/pages/${path}`;
  uni.navigateTo({ url });
}

function navBack(opt: { delta: number } = { delta: 1 }) {
  // #ifdef H5
  const pages = getCurrentPages();
  if (pages.length > 1) {
    uni.navigateBack(opt);
  } else {
    const { delta } = opt;
    history.go(-delta);
  }
  // #endif
  // #ifndef H5
  uni.navigateBack(opt);
  // #endif
}

function navToTab(tab: 'index' | 'filling' | 'mine' | 'gemstone') {
  const url = `/pages/index/${tab}`;
  uni.switchTab({ url });
}

function redirectTo(path: string) {
  const url = `/pages/${path}`;
  uni.redirectTo({ url });
}

export { navTo, navBack, navToTab, redirectTo };
